package com.enjoyor.soa.traffic.core.tsms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.tsms.domain.CommonPlace;
import com.enjoyor.soa.traffic.core.tsms.mapper.ICommonPlaceMapper;
import com.enjoyor.soa.traffic.core.tsms.mapper.impl.CommonPlaceMapper;
import com.enjoyor.soa.traffic.core.tsms.service.ICommonPlaceService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;

@Service
@Transactional
@SuppressWarnings("rawtypes")
public class CommonPlaceService implements ICommonPlaceService {
	@Autowired 
	private ICommonPlaceMapper iCommonPlaceMapper;
	
	@Autowired
	private IPubLogMapper pubLogMapper;
	
	@Override
	public Page getCommonPlacePage(Page page,String commonPlaceId,String commonPlaceName,String placeTypeId,String placeTypeName,String placeAddress,String createPerson,String createTime,String placePerson) {
		// TODO Auto-generated method stub
		Map<String,String> mapBean = new HashMap<String,String>();
    	mapBean.put("commonPlaceId", commonPlaceId);
    	mapBean.put("commonPlaceName", commonPlaceName);
    	mapBean.put("placeTypeId", placeTypeId);
    	mapBean.put("placeTypeName", placeTypeName);
    	mapBean.put("placeAddress", placeAddress);
    	mapBean.put("createPerson", createPerson);
    	mapBean.put("createTime", createTime);
    	mapBean.put("placePerson", placePerson);
    	page.setMapBean(mapBean);
		return iCommonPlaceMapper.selectPageInfo(page);
	}

	@Override
	public List<CommonPlace> getCommonPlaceList(String commonPlaceId,String commonPlaceName,String placeTypeId,String placeTypeName,String placeAddress,String createPerson,String createTime,String placePerson) {
		// TODO Auto-generated method stub
		Map<Object, Object> map = new HashMap<>();
		map.put("commonPlaceId", commonPlaceId);
		map.put("commonPlaceName", commonPlaceName);
		map.put("placeTypeId", placeTypeId);
		map.put("placeTypeName", placeTypeName);
		map.put("placeAddress", placeAddress);
		map.put("createPerson", createPerson);
		map.put("createTime", createTime);
		map.put("placePerson", placePerson);
		return iCommonPlaceMapper.selectList(map);
	}

	@Override
	public String insert(CommonPlace commonPlace, String personName) {
		// TODO Auto-generated method stub
		String commonPlaceId = "CP" + TimeHelper.getUniqueString();
		commonPlace.setCommonPlaceId(commonPlaceId);
		commonPlace.setCreatePerson(personName);
		commonPlace.setCreateTime(TimeHelper.dateToLongString());
		commonPlace.setUpdateTime(TimeHelper.dateToLongString());
		commonPlace.setIsDelete(false);
		iCommonPlaceMapper.insert(commonPlace);
		pubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
                String.format("添加常备单位:{%s} 操作成功!", new Object[] { commonPlace.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.TSMS_COMMON_PLACE_MANAGEMENT.getMessage());
		return commonPlaceId;
	}

	@Override
	public void update(CommonPlace commonPlace, String personName) {
		// TODO Auto-generated method stub
		commonPlace.setUpdateTime(TimeHelper.dateToLongString());
		iCommonPlaceMapper.updateByIdSelective(commonPlace);
		 pubLogMapper.saveNoramlLogInfo(personName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
	                String.format("修改常备单位成功:{%s} 操作成功!", new Object[] { commonPlace.getId() }),
	                LogInfoDic.LOG_MODULAR_ENUM.TSMS_COMMON_PLACE_MANAGEMENT.getMessage());
	}

	@Override
	public void delete(String commonPlaceId, String personName) {
		// TODO Auto-generated method stub
		iCommonPlaceMapper.deleteById(commonPlaceId);
	     pubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_DELETE.getCode(),
	                String.format("删除常备单位:{%s} 操作成功!", new Object[] { commonPlaceId }),
	                LogInfoDic.LOG_MODULAR_ENUM.TSMS_COMMON_PLACE_MANAGEMENT.getMessage());
	}
}
